<template>
  <div>
    <h3>忘记密码</h3>
    <br />
    <p>账&emsp;&emsp;号：<input type="text" v-model="data.name" /></p>
    <br />
    <p>密&emsp;&emsp;码：<input type="text" v-model="data.password" /></p>
    <br />
    <p>确认密码：<input type="text" v-model="data.pwd" /></p>
    <br />
    <p>手&ensp;机&ensp;号：<input type="text" v-model="data.mobile" /></p>
    <br />
    <p>
      验&ensp;证&ensp;码：<input
        type="text"
        v-model="data.sms_code"
        style="width: 50px"
      />&emsp; <button @click="SmsCode">发送验证码</button>
    </p>
    <br />
    <p><button @click="update">确认修改</button></p>
    <br />
  </div>
</template>

<script>
import Axios from "axios";
export default {
  name: "",
  data() {
    return {
      data: {
        name: "",
        password: "",
        pwd: "",
        mobile: "",
        sms_code: "",
      },
    };
  },
  props: {},

  components: {},

  created() {},

  mounted() {},

  methods: {
    // 发送短信验证码
    SmsCode() {
      Axios.post("http://127.0.0.1:8000/api/users/sms_code/", this.data).then(
        (res) => {
          console.log(res);
          if (res.data.code == 200) {
            this.$notify({
              title: "成功",
              message: "发送短信验证码成功",
              type: "success",
            });
          } else {
            this.$notify.error({
              title: "错误",
              message: res.data.message,
            });
          }
        }
      );
    },
    update() {
      Axios.put("http://127.0.0.1:8000/api/users/forget/", this.data).then(
        (res) => {
          console.log(res);
          if (res.data.code == 200) {
            this.$notify({
              title: "成功",
              message: "密码修改成功去登录吧",
              type: "success",
            });
            this.$router.push("/");
          } else {
            this.$notify.error({
              title: "错误",
              message: res.data.message,
            });
          }
        }
      );
    },
  },

  computed: {},

  watch: {},

  directives: {},

  filters: {},
};
</script>

<style>
* {
  margin: 0;
}
</style>
